package com.example.its2021606134chh.BusDiyModule;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.its2021606134chh.MainActivity;
import com.example.its2021606134chh.R;

public class BusDiyPlaceActivity extends AppCompatActivity {

    private ImageView imgBusPlaceBack;
    private TextView tvBusPlaceStartEnd;
    private TextView tvBusPlaceUser;
    private TextView tvBusPlacePhone;
    private Spinner spStartPlace;
    private Spinner spEndPlace;
    private Button btnBusPlaceNext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bus_diy_place);
        initView();
        Intent intent1 = getIntent();
        String id = intent1.getStringExtra("id");
        String start_place = intent1.getStringExtra("start_place");
        String end_place = intent1.getStringExtra("end_place");
        String price = intent1.getStringExtra("price");
        String sDate = intent1.getStringExtra("sDate");
        String user = "张三";
        String phone_number = "13111111111";
        tvBusPlaceStartEnd.setText(start_place + "—" + end_place);
        tvBusPlaceUser.setText(user);
        tvBusPlacePhone.setText(phone_number);

        imgBusPlaceBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(BusDiyPlaceActivity.this, MainActivity.class));
                finish();
            }
        });
        btnBusPlaceNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String sStartPlace = spStartPlace.getSelectedItem().toString();
                String sEndPlace = spEndPlace.getSelectedItem().toString();
                if (sStartPlace.equals(sEndPlace)) {
                    Toast.makeText(BusDiyPlaceActivity.this, "上下车地点不能选择同一个站点", Toast.LENGTH_SHORT).show();
                } else {
                    String sUser = tvBusPlaceUser.getText().toString().trim();
                    String sPhone = tvBusPlacePhone.getText().toString().trim();
                    Intent intent = new Intent(BusDiyPlaceActivity.this, BusConfirmOrderActivity.class);
                    intent.putExtra("busstop_date", sDate);
                    intent.putExtra("id", id);
                    intent.putExtra("start_place", start_place);
                    intent.putExtra("end_place", end_place);
                    intent.putExtra("real_start_place", sStartPlace);
                    intent.putExtra("real_end_place", sEndPlace);
                    intent.putExtra("price", price);
                    intent.putExtra("user", sUser);
                    intent.putExtra("phone_number", sPhone);
                    startActivity(intent);
                    finish();
                }
            }
        });

    }

    private void initView() {
        imgBusPlaceBack = (ImageView) findViewById(R.id.imgBusPlaceBack);
        tvBusPlaceStartEnd = (TextView) findViewById(R.id.tvBusPlaceStartEnd);
        tvBusPlaceUser = (TextView) findViewById(R.id.tvBusPlaceUser);
        tvBusPlacePhone = (TextView) findViewById(R.id.tvBusPlacePhone);
        spStartPlace = (Spinner) findViewById(R.id.spStartPlace);
        spEndPlace = (Spinner) findViewById(R.id.spEndPlace);
        btnBusPlaceNext = (Button) findViewById(R.id.btnBusPlaceNext);
    }
}